package com.tigercar.servicemanagement.controller;

import com.tigercar.common.pojo.PageResult;
import com.tigercar.servicemanagement.dto.UserDTO;
import com.tigercar.servicemanagement.pojo.Employee;
import com.tigercar.servicemanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 查询用户
     */
    @GetMapping("/search")
    public ResponseEntity<PageResult<UserDTO>> findUser(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "rows",defaultValue = "10") Integer rows,
            @RequestParam(value = "key",required = false) String key){
        PageResult<UserDTO> pageResult = userService.findUser(page,rows,key);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 新增用户
     */
    @PostMapping("/add")
    public ResponseEntity<Void> addUser(
            @RequestParam("employeename") List<String> employeename,
            @RequestParam("rolename") List<Integer> rolename,
            @RequestParam("password") String password,
            @RequestParam("rePassword") String rePassword,
            Employee employee){
        userService.addUser(employeename,rolename,password,rePassword,employee);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
}
